////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   PartyCode.java
// AUTHOR           :   ric.yik
// DATE CREATE      :   Feb 3, 2006
// DESCRIPTION      :   
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// Feb 3, 2006      ric.yik         1.0                 source is created.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.common.web;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

import com.erp.app.common.ProjectConstants;

/**
 * Prefix for Vendor Code or Customer Code
 * @author Ric Yik
 */
public class PartyCodePrefix {

    private final Map prefixes = new TreeMap();

    private String prefixHead;

    private String prefix;

    protected void populatePrefixes() {
        this.prefixes.clear();
        for (int i = 0; i < ProjectConstants.A_TO_Z.length; ++i) {
            String concatenatedPrefix = this.getPrefixHead() + ProjectConstants.A_TO_Z[i];
            this.prefixes.put(concatenatedPrefix, concatenatedPrefix);
        }
    }

    public PartyCodePrefix() {
        super();
    }

    public PartyCodePrefix(String head) {
        this();
        this.setPrefixHead(head);
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Iterator getPrefixes() {
        return prefixes.entrySet().iterator();
    }

    public String toString() {
        return this.getPrefix();
    }

    public String getPrefixHead() {
        return prefixHead;
    }

    public void setPrefixHead(String prefixHead) {
        this.prefixHead = prefixHead;
        this.populatePrefixes();
    }

    public void setPrefixFromPartyCode(String partyCode, String newPrefixHead) {
        this.setPrefix(newPrefixHead + String.valueOf(partyCode.charAt(this.getPrefixHead().length())));
        this.setPrefixHead(newPrefixHead);
    }

}
